﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Insteon.Messages.Insteon;

namespace Insteon.Commands.Insteon
{
    internal class StartAllLinkCommand : Command
    {

        internal readonly LinkCode.Codes LinkCode;
        internal readonly byte Group;

        internal StartAllLinkCommand(LinkCode.Codes LinkCode, byte Group)
        {
            this.LinkCode = LinkCode;
            this.Group = Group;

            buffer = new byte[4];
            buffer[0] = 0x02;
            buffer[1] = 0x64;
            buffer[2] = (byte) LinkCode;
            buffer[3] = Group;
        }

        internal override bool IsResponse(Messages.Message Message)
        {
            if (!(Message is Messages.Insteon.StartAllLinkResponse))
            {
                return false;
            }
            StartAllLinkResponse Response = (StartAllLinkResponse)Message;
            if ((Response.LinkCode == (byte)this.LinkCode) && (Response.Group == this.Group))
            {
                ModemCompleted = true;
                ModemResponse = Message;
                if (Response.Status.Status == ResponseStatus.Statuses.ACK)
                {
                    this.Succeed();
                }
                else
                {
                    this.Fail();
                }
                return true;
            }
            return false;
        }
    }
}
